use strict;
use warnings;

use Test::More;
use Test::Base;

use MT::App::Test;
use File::Basename;
plan tests => (3 + &blocks);

my $app = MT::App::Test->test_instance_of(
	#force_initialize_database => 1,
	data_dirs => dirname(File::Spec->rel2abs(__FILE__)),
);

sub Test::Base::Filter::template_build {
	my ($self, $str) = @_;
	$app->test_template_build(\$str);
}

sub Test::Base::Filter::php_template_build {
	my ($self, $str) = @_;
	$app->test_php_template_build(\$str);
}

filters {
	input => [qw( chomp )],
	expected => [qw( chomp )],
};


ok(
	$app->test_template_load_context('ctx_1'),
	'test_template_load_context'
);

(my $tmpl_file = __FILE__) =~ s/\.t$/.tmpl/;
like(
	$app->test_template_build($tmpl_file),
	qr/^\s*file\s*$/,
	'test_template_build - in file'
);
like(
	$app->test_php_template_build($tmpl_file),
	qr/^\s*file\s*$/,
	'test_php_template_build - in file'
);

my $testable = $app->test_is_php_testable;
run {
	my $block = shift;
	SKIP: {
		if (! $testable && $block->name =~ m/test_php_template_build/) {
			skip("Can't test test_php_template_build()", 1);
		}
		is($block->input, $block->expected, $block->name);
	}
};

__END__

=== test_template_build - Unless
--- input template_build
<mt:Unless>abc</mt:Unless>
--- expected
abc

=== test_php_template_build - Unless
--- input php_template_build
<mt:Unless>abc</mt:Unless>
--- expected
abc

=== test_template_build - BlogID
--- input template_build
<mt:BlogID>
--- expected
2

=== test_php_template_build - BlogID
--- input php_template_build
<mt:BlogID>
--- expected
2

=== test_template_build - EntryID
--- input template_build
<mt:EntryID>
--- expected
2

=== test_php_template_build - EntryID
--- input php_template_build
<mt:EntryID>
--- expected
2

=== test_template_build - Var
--- input template_build
<mt:GetVar name="var1">
--- expected
one

=== test_php_template_build - Var
--- input php_template_build
<mt:GetVar name="var1">
--- expected
one
